import { defineStore } from "pinia";
import { ref } from "vue";
import {getLoginUserUsingGet} from "@/api/userController";

/**
 * 存储登录用户信息的状态
 */
export const useLoginUserStore = defineStore("loginUser", () => {
  const loginUser = ref<API.LoginUserVO>({
    userName: "未登录",
  });

  /**
   * 远程获取登录用户信息
   */
  async function fetchLoginUser() {
    //todo 由于后端还没提供接口，暂时注释
    const res = await getLoginUserUsingGet( );
    if (res.data.code === 0 && res.data.data) {
      loginUser.value = res.data.data;
    }
  }

  function setLoginUser(newLoginUser: any) {
    loginUser.value = newLoginUser;
  }

  return { loginUser, setLoginUser, fetchLoginUser };
});
